package com.ruoyi.system.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.TReturnedOrders;
import com.ruoyi.system.service.ITReturnedOrdersService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 退货单信息Controller
 * 
 * @author ruoyi
 * @date 2024-05-22
 */
@RestController
@RequestMapping("/system/orders")
public class TReturnedOrdersController extends BaseController
{
    @Autowired
    private ITReturnedOrdersService tReturnedOrdersService;

    /**
     * 查询退货单信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TReturnedOrders tReturnedOrders)
    {
        startPage();
        List<TReturnedOrders> list = tReturnedOrdersService.selectTReturnedOrdersList(tReturnedOrders);
        return getDataTable(list);
    }

    /**
     * 导出退货单信息列表
     */
    @Log(title = "退货单信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TReturnedOrders tReturnedOrders)
    {
        List<TReturnedOrders> list = tReturnedOrdersService.selectTReturnedOrdersList(tReturnedOrders);
        ExcelUtil<TReturnedOrders> util = new ExcelUtil<TReturnedOrders>(TReturnedOrders.class);
        util.exportExcel(response, list, "退货单信息数据");
    }

    /**
     * 获取退货单信息详细信息
     */
    @GetMapping(value = "/{returnedOrdersId}")
    public AjaxResult getInfo(@PathVariable("returnedOrdersId") String returnedOrdersId)
    {
        return success(tReturnedOrdersService.selectTReturnedOrdersByReturnedOrdersId(returnedOrdersId));
    }

    /**
     * 新增退货单信息
     */
    @Log(title = "退货单信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TReturnedOrders tReturnedOrders)
    {
        String id= SecurityUtils.getUserId().toString();
        tReturnedOrders.setReturnedOrdersId(id+"_"+System.currentTimeMillis());
        tReturnedOrders.setRefund("0");
        tReturnedOrders.setStatus("1");
        tReturnedOrders.setUpdateBy(id);
        System.out.println(tReturnedOrders.toString());
        return toAjax(tReturnedOrdersService.insertTReturnedOrders(tReturnedOrders));
    }

    /**
     * 修改退货单信息
     */
    @Log(title = "退货单信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TReturnedOrders tReturnedOrders)
    {
        return toAjax(tReturnedOrdersService.updateTReturnedOrders(tReturnedOrders));
    }

    /**
     * 删除退货单信息
     */
    @Log(title = "退货单信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{returnedOrdersIds}")
    public AjaxResult remove(@PathVariable String[] returnedOrdersIds)
    {
        return toAjax(tReturnedOrdersService.deleteTReturnedOrdersByReturnedOrdersIds(returnedOrdersIds));
    }
}
